package com.zwl.test;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

/**
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * ┃　　　┃   神兽保佑
 * ┃　　　┃   代码无BUG！
 * ┃　　　┗━━━┓
 * ┃　　　　　　　┣┓
 * ┃　　　　　　　┏┛
 * ┗┓┓┏━┳┓┏┛
 * ┃┫┫　┃┫┫
 * ┗┻┛　┗┻┛
 * create by 2017/3/22 9:32
 * annotation:
 */
public class DialogActivity extends Activity {

    private Context mContext;
    private AlertDialog alertDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);

        mContext = this;

        initDialog();
    }

    private void initDialog() {

        showDialogIsStatusChanged();
    }

    private void showDialogIsStatusChanged() {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        alertDialog = builder.create();
        alertDialog.setCanceledOnTouchOutside(false);
        View inflateDialogView = View.inflate(mContext, R.layout.activity_alertdialog, null);


        TextView tIgnore = (TextView) inflateDialogView.findViewById(R.id.text_ignore);

        tIgnore.setOnClickListener(getClickListener());

        //SET ADAPTER
        ListView mListView = (ListView) inflateDialogView.findViewById(R.id.mListView);
        mListView.setAdapter(new PopDialogAdapter(mContext));


        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                System.out.println("dian ji :"+i);
            }
        });
        alertDialog.setView(inflateDialogView);
        alertDialog.show();
    }

    @NonNull
    private View.OnClickListener getClickListener() {
        return new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                switch (view.getId()){

                   case  R.id.text_ignore:

                       alertDialog.dismiss();
                    break;
                }
            }
        };
    }
}
